<?php

namespace Common\Controller;

use Think\Controller;

class MyController extends Controller {

  function __construct() {
    parent::__construct();
    
    if ( C('LICENSE_METHOD') == 'SERVER' ) {
      $this->_license_server();
    } elseif ( C('LICENSE_METHOD') == 'TIME' )  {
      $this->_license_time();
    } else {
      gameover('授权错误');
    }
  }
  
  /**
   * 服务器授权
   */
  protected function _license_server() {
    $default_cpu_id = 'd34d594b8ab56abec5a50b62dec06a91';
    $cpu_id = md5(getenv('PROCESSOR_IDENTIFIER') . getenv('PROCESSOR_REVISION')) ;
    if ( $default_cpu_id !== $cpu_id ) {
      gameover('服务器未授权');
    }
  }
  
  protected function _license_time() {
    $expire_time_str = '2015-12-31' ;
    $expire_time = strtotime($expire_time_str);
    if ( $expire_time < time() ) {
      gameover('授权时间到' . $expire_time_str .'截止');
    } 
  }
}
